       <template>
    <div>
        <div class="one">
            <el-form ref="form" :model="form" label-width="80px" v-if="show">
                <el-form-item label="仓库名称" class="size" prop="wId">
                    <el-input v-model="form.wId" placeholder="请输入名称"></el-input>
                </el-form-item>
                <el-form-item label="货架名称" class="size" prop="name">
                    <el-input v-model="form.name" placeholder="请输入名称"></el-input>
                </el-form-item>
                <el-form-item label="占用标志" prop="occupy">
                    <el-select v-model="form.occupy" placeholder="请选择">
                        <el-option label="停用" value="0"></el-option>
                        <el-option label="启用" value="1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item class="item">
                    <el-button type="primary" icon="el-icon-search" @click="getData()">搜索</el-button>

                    <el-button icon="el-icon-refresh-left" @click="Reset()">重置</el-button>
                </el-form-item>
            </el-form>
            <div class="Newexportsearchrefresh">
                <div class="Addexport">
                    <el-button type="primary" plain icon="el-icon-plus" @click="addLists()">新增</el-button>
                    <el-button type="warning" plain icon="el-icon-download" class="yello-button" @click="exports()">导出</el-button>
                </div>
                <div class="Searchrefresh">
                    <el-tooltip placement="top">
                        <div slot="content">{{ disabled ? '显示搜索' : '隐藏搜索' }}</div>
                        <el-button icon="el-icon-search" circle @click="Showorhide()"> </el-button>
                    </el-tooltip>
                    <el-tooltip content="刷新" placement="top">
                        <el-button icon="el-icon-refresh-left" circle @click="Reset()"></el-button>
                    </el-tooltip>
                </div>
            </div>
        </div>
        <el-table :data="tableData"  style="width: 100%">
            <el-table-column label="序号" width="100" type="index" align="center" :index="indexMethod"> </el-table-column>
            <el-table-column prop="belongName" label="仓库名称" width="160" align="center"> </el-table-column>
            <el-table-column prop="name" label="货架名称" width="150" align="center"> </el-table-column>
            <el-table-column prop="code" label="货架条码" width="170" align="center"> </el-table-column>
            <el-table-column prop="volume" label="容量上限(立方米)" width="170" align="center"> </el-table-column>
            <el-table-column prop="weight" label="重量上限(KG)" width="170" align="center"> </el-table-column>
            <el-table-column prop="occupy" label="占用标志" width="120" align="center">
                <template slot-scope="scope">
                    {{ scope.row.occupy == 0 ? '停用' : '启用' }}
                </template>
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="200" align="center">
                <template slot-scope="scope">
                    <el-button type="text" size="small" @click="update(scope.row)">修改</el-button>
                    <el-button type="text" size="small" @click="delet(scope.row.sId)">删除</el-button>
                    <el-button type="text" size="small" @click="see(scope.row.sId)">查看</el-button>
                    <el-button type="text" size="small" @click="Print(scope.row.code)">打印条形码</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="block">
            <el-pagination
            style="float:right;"
            background
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="form.pageNum"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="form.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
            >
            </el-pagination>
        </div>
        <!-- 修改和添加弹窗 -->
        <div class="box">
        <el-dialog :title="Dialogtitle" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
            <el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <el-form-item label="仓库" prop="wId">
                    <el-select v-model="ruleForm.wId" placeholder="请选择">
                        <el-option v-for="item in options" :key="item.wId" :label="item.name" :value="item.wId"> </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="货架名称" prop="name">
                    <el-input v-model="ruleForm.name"></el-input>
                </el-form-item>
                <el-form-item label="货架条码" prop="code">
                    <el-input v-model="ruleForm.code"></el-input>
                </el-form-item>
                <el-form-item label="容量上限（立方米）" prop="volume">
                    <el-input v-model="ruleForm.volume"></el-input>
                </el-form-item>
                <el-form-item label="重量上限（KG）" prop="weight">
                    <el-input v-model="ruleForm.weight"></el-input>
                </el-form-item>
                <el-form-item label="占用标志" prop="occupy">
                    <el-select v-model="ruleForm.occupy" placeholder="请选择占用标志">
                        <el-option v-for="item in option" :key="item.occupy" :label="item.label" :value="item.occupy"> </el-option>
                        <!-- <el-option label="停用" value=0></el-option>
                        <el-option label="启用" value=1></el-option> -->
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
                    <el-button @click="dialogVisible = false">取 消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
        </div>
        <!-- 查看弹窗 -->
        <el-dialog title="查看货品" :visible.sync="dialogTableVisible">
            <el-table :data="gridData">
                <el-table-column type="index" label="序号" width="150"></el-table-column>
                <el-table-column property="name" label="货品名称" width="200"></el-table-column>
                <el-table-column property="sku" label="sku"></el-table-column>
                <el-table-column property="stock" label="库存数量"></el-table-column>
                <el-table-column property="stock" label="可用库存"></el-table-column>
                <el-table-column property="remark" label="商品描述"></el-table-column>
            </el-table>
            <div class="block" v-show="tue">
            <el-pagination
            style="float:right;"
            v-show="tue"
            background
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="form.pageNum"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="form.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="tatal"
            >
            </el-pagination>
        </div>
        </el-dialog>
        <div class="syu">
         <el-dialog title="打印条形码" :visible.sync="dialogbarcode">
             <!-- <template> -->
                 <div id="printMe">
                     <svg id="barcode"></svg>
                 </div>
                 
             <!-- </template> -->
             <div class="bu" style="display:flex; justify-content:flex-end">
                 <el-button @click="dialogbarcode = false">取 消</el-button>
    <el-button v-print="'#printMe'" type="primary" @click="dialogbarcode = false">打印</el-button>
             </div>
         </el-dialog>
         </div>
    </div>
</template>

<script>
import { Shelfdata, Shelfmodification, Shelfdeletion, Warehousedata, Shelfaddition, Viewshelves } from '@/api/user';
import Icon from './Icon.vue';
export default {
    components: { Icon },
    data() {
        return {
            // 打印
             printObj:{
            id:'printMe',
            //其他配置项，
         },
            // 查看弹窗
            dialogTableVisible: false,
            // 查看弹窗表格
            gridData: [],
            // 停用启用
            option: [
                {
                    occupy: 0,
                    label: '停用'
                },
                {
                    occupy: 1,
                    label: '启用'
                }
            ],
            //仓库名称
            options: [],
            // 新增表单验证
            // 弹窗标题
            Dialogtitle: '',
            // 弹窗
            ruleForm: {
                name: '',
                wId: '',
                code: '',
                volume: '',
                weight: '',
                occupy: ''
            },
            // 新增和修改
            conVar: '',
            // 总条目数
            total: 100,
            // 搜索
            form: {
                name: '',
                wId: '',
                occupy: '',
                pageNum: 1,
                pageSize: 10
            },
            from:{
pageNum: 1,
                pageSize: 10
            },
            // 数据
            tableData: [],
            disabled: false,
            show: true,
            dialogVisible: false,
            tatal:undefined,
            tue:false,
            dialogbarcode:false
        };
    },
    methods: {
        // 查看
        see(sId) {
            this.dialogTableVisible = true;
            console.log(sId);
            this.from.sId = sId 
            Viewshelves(this.from).then((ref) => {
                console.log(ref);
                if(ref.rows == ''){
                    this.tue = false
                }else{
                    this.tue = true
                }
                this.gridData = ref.rows;
                this.tatal = ref.total
            });
        },
        // 删除
        delet(sId) {
            console.log(sId);
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    Shelfdeletion(sId).then((ref) => {
                        if (ref.code == 200) {
                            this.getData();
                            this.$message({
                                type: 'success',
                                message: ref.msg
                            });
                        } else {
                            this.$message({
                                type: 'success',
                                message: ref.msg
                            });
                        }
                    });
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
        },
        // 新增和修改
        submitForm(formName) {
            if (this.conVar == 0) {
                Shelfaddition(this.ruleForm).then((ref) => {
                    this.getData();
                    this.dialogVisible = false;
                    if (ref.code == 200) {
                        this.$message({
                            message: ref.msg,
                            type: 'success'
                        });
                    } else {
                        this.$message.error(ref.msg);
                    }
                });
            } else {
                Shelfmodification(this.ruleForm).then((ref) => {
                    this.dialogVisible = false;
                    if (ref.code == 200) {
                        this.$message({
                            message: ref.msg,
                            type: 'success'
                        });
                    } else {
                        this.$message.error(ref.msg);
                    }
                });
            }
        },
        // 仓库名称
        belongName() {
            Warehousedata().then((ref) => {
                console.log(ref);
                this.options = ref.rows;
            });
        },
        // 重置弹窗里的内容
        resect() {
            (this.ruleForm.name = undefined),
                (this.ruleForm.wId = undefined),
                (this.ruleForm.code = undefined),
                (this.ruleForm.volume = undefined),
                (this.ruleForm.weight = undefined),
                (this.ruleForm.occupy = undefined);
        },
        // 弹窗确认关闭
        handleClose(done) {
            this.$confirm('确认关闭？')
                .then((_) => {
                    done();
                })
                .catch((_) => {});
        },
        // 新增
        addLists() {
            this.resect();
            this.dialogVisible = true;
            this.Dialogtitle = '添加仓库货架';
            this.conVar = 0;
        },
        // 修改
        update(e) {
            this.ruleForm = e;
            console.log(typeof this.ruleForm.occupy);
            this.Dialogtitle = '修改仓库货架';
            this.conVar = 1;
            this.dialogVisible = true;
        },
        // 刷新和重置
        Reset() {
            this.$refs.form.resetFields();
            this.getData();
        },
        // 搜索框显示隐藏
        Showorhide() {
            (this.show = !this.show), (this.disabled = !this.disabled);
        },
        // 分页（多少个）
        handleSizeChange(val) {
            this.form.pageSize = Number(val);
            this.getData();
        },
        // 分页（页数）
        handleCurrentChange(val) {
            this.form.pageNum = Number(val);
            this.getData();
        },
        // 搜索数据
        getData() {
            Shelfdata(this.form).then((ref) => {
                // console.log(ref);
                this.tableData = ref.rows;
                this.total = ref.total;
            });
        },
        // 序号
        indexMethod(index) {
            return (this.form.pageNum - 1) * this.form.pageSize + index + 1;
        },
        // 打印条形码
        Print(val){
            this.dialogbarcode =true
            setTimeout(() => {

JsBarcode("#barcode",val)
}, 0)
    

        }
    },
    mounted() {
        this.getData();
        this.belongName();
    }
};
</script>
<style scoped lang="less">
.size {
    font-weight: 550;
}
.one .el-form-item--small {
    width: 20%;
    display: inline-block;
}
.item /deep/ .el-form-item__content:last-child {
    margin-left: 20px !important;
}
.item /deep/ .el-button {
    height: 30px !important;
}
.Addexport /deep/ .el-button {
    widows: 70px !important;
}
/deep/ .yello-button {
    color: #ffba00;
    background: #fff8e6;
    border-color: #ffe399;
}
.Newexportsearchrefresh {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}
/deep/ .el-table th.el-table__cell.is-leaf {
    border: unset !important;
}
.box /deep/.el-dialog {
    width: 50% !important;
}
.box .el-dialog__body /deep/.el-form-item--small {
    width: 80% !important;
}
/deep/.el-select {
    width: 100% !important;
}
.block{
    height: 20px;
    margin-top: 10px;
}
.syu /deep/.el-dialog{
    width: 35% !important;
}
#printMe{
    text-align: center;
}
</style>